﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paringregkaardid_paring", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(ParingregkaardidParing))]
    public class ParingregkaardidParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParingregkaardidParing clazz;
        
        public ParingregkaardidParingSerializer(IParingregkaardidParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ariregistri_kood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("kehtivus");
            if (clazz.Kehtivus!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_regkaardi_kehtivus");
                Writer.WriteString(clazz.Kehtivus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kehtivus");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringregkaardid_paring>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringregkaardid_paring>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="kehtivus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringregkaardid_paring>kehtivus");
                }
                clazz.Kehtivus = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XRegkaardiKehtivus(Reader.ReadElementString("kehtivus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringregkaardid_paring>kehtivus", Reader.LocalName);
            }
        }
    }
}
